//id要与html的dom-module的id保持一致
Polymer({
    is: 'PC-CARD-HTML-4906798803222258-01',
    properties: {
        widget_title: {
            type: String,
            export: true,
            default: "处室通知"
        },
        thumbnail: {
            type: String,
            export: true,
            default: "thumbnail.png"
        },
        target_platform: {
            type: String,
            export: true,
            default: "WEB"
        },
        params: {
            type: String,
            export: true,
            default: "true"
        },
        param_file: {
            type: String,
            export: true,
            default: "params.xml"
        },
        show_published: {
            type: String,
            export: true,
            default: "true"
        },
        index_page_num: {
            type: String,
            export: true,
            default: "10"
        },
        icon: {
            type: String
        },
        notice_arr: {
            type: Array
        },
        noneData: {
            type: String
        },
        hasDataFlag: {
            type: String
        }
    },
    ready: function () {
        //请求数据和展现
        var widget = this;
        var notices = "";
        var params = {
            "showPublished": widget.show_published,
            "indexPageNum": widget.index_page_num
        };

        var pageNum = typeof(params.indexPageNum) == 'undefined' ? '4' : params.indexPageNum;

        $.ajax({
            type: 'GET',
            url: "http://ehall.sdut.edu.cn/openoa/getXxwjList.do?rootId=10002&num=" + pageNum,
            //traditional : true,
            //async: false,
            data: params || {},
            dataType: 'json',
            success: function (resp) {
                notices = resp;
                if (notices) {
                    var data = notices.xxwj;
                    var dataLen = data ? data.length : 0;
                    data.length = dataLen;
                    widget.notice_arr = data;
                    widget.show_published_time = typeof (params.showPublished) == 'undefined' ? true : params.show_published;
                    widget.fire("widgetComplete");
                    widget.noneData = false;
                    widget.hasDataFlag = true;
                } else {
                    widget.noneData = true;
                    widget.hasDataFlag = false;
                }
            },
            error: function () {
                widget.fire("widgetComplete");
            }
        });
    },
    goMorePage: function () {
        var MORE_PATH = "http://bgxt.sdut.edu.cn"; //bulletin更多页面地址
        window.open(MORE_PATH, "_blank");
    },
    formatDate: function (value, fmt) {
        var o = {
            "M+": value.getMonth() + 1, //月份
            "d+": value.getDate(), //日
            "h+": value.getHours(), //小时
            "m+": value.getMinutes(), //分
            "s+": value.getSeconds(), //秒
            "q+": Math.floor((value.getMonth() + 3) / 3), //季度
            "S": value.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    },
    getDate: function (value) {
        value = value.replace(/-/g, '/');
        var today = this.formatDate(new Date(), "yyyy/MM/dd");
        var yd = new Date();
        yd.setDate(yd.getDate() - 1);
        var yesterday = this.formatDate(yd, "yyyy/MM/dd");
        var pubdate = this.formatDate(new Date(value), "yyyy/MM/dd");
        if (today == pubdate)
            return "今天";
        else if (yesterday == pubdate)
            return "昨天";
        else {
            var newDate = new Date(value);
            return (newDate.getMonth() + 1) + '-' + newDate.getDate();
        }
    },
    isToday: function (value) {
        value = value.replace(/-/g, '/');
        var today = this.formatDate(new Date(), "yyyy/MM/dd");
        var yd = new Date();
        yd.setDate(yd.getDate() - 1);
        var yesterday = this.formatDate(yd, "yyyy/MM/dd");
        var pubdate = this.formatDate(new Date(value), "yyyy/MM/dd");
        if (today == pubdate)
            return true;
        else if (yesterday == pubdate)
            return false;
    }

});